package mop.controller;

import java.util.List;

import mop.exception.IllegalIdException;
import mop.model.World;
import mop.model.user.User;
import mop.model.user.UserInterface;

/**
 * LoginUserController
 * 
 * Use case controller for logging in a user. 
 * (CUSTOM USE CASE)
 * 
 * @author	MOP Team 7
 */
public class LoginUserController extends UseCaseController
{

	/**
	 * Creates a LoginUserController.
	 * 
	 * @see UseCaseController#UseCaseController(World)
	 */
	public LoginUserController(World world)
	{
		super(world);
	}
	
	/**
	 * CUSTOM Use case : User login
	 * 
	 * @param	name
	 * 			The username of the user.
	 * @effect	Set the current user to given user
	 * 		| super.getWorld().setCurrentUser(newCurrentUser)
	 * @throws	IllegalIdException 
	 * 			Thrown when the given username is not in the database
	 */
	public UserInterface loginUser(String name) 
		throws IllegalIdException
	{
		User newCurrentUser = getWorld().getUserDataBase().find(name);
		super.getWorld().setCurrentUser(newCurrentUser);
		return newCurrentUser;
	}
	
	/**
	 * @see UseCaseController#getWorld().getAllUsers()
	 */
	public List<UserInterface> getUserList()
	{
		return super.getAllUsers();
	}
	
	/**
	 * @see UseCaseController#getWorld().getCurrentUser()
	 */
	public UserInterface getCurrentUser()
	{
		return super.getWorld().getCurrentUser();
	}
	
	/***************************************************************************
	 * 								Visit
	 ***************************************************************************/
	
	/**
	 * Make a CallBack to the visitor
	 * @param v the visitor
	 */
	public void visit(ControllerVisitor v)
	{
		v.action(this);
	}
	
}